<template>
  <div class="app-container">
    <div v-show="type == 0 || type == 2">
      <el-row>
        <!-- <el-col :span="5">
        <MainType :typeCode="typeCode" @getNode="getNode" ></MainType>
      </el-col> -->
        <el-col :span="24">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-row>
              <el-col>
                <el-form-item label="项目名称" prop="projectName">
                  <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable
                    @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="状态" prop="status">
                  <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
                    <el-option v-for="dict in dict.type.project_status" :key="dict.value" :label="dict.label"
                      :value="dict.value" />
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-col>

            </el-row>
          </el-form>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddZJ">新增</el-button>
            </el-col>
            <!-- <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddWX">外协项目</el-button>
            </el-col> -->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
          <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" height="400" border
            v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
            <el-table-column label="序号" type="index" :index="indexMethod" align="center" />
            <el-table-column label="项目编号" align="center" prop="projectNo" width="120" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <!-- Assuming your prop name is regiEnterprise -->
                <a @click="handleSelect(scope.row, scope.$index)" class="hyperlink">
                  {{ scope.row.projectNo }}
                </a>
              </template>
            </el-table-column>

            <el-table-column label="项目名称" align="center" prop="projectName" :show-overflow-tooltip="true" width="210" />
            <el-table-column label="项目负责人" align="center" prop="projectHead" width="85" show-overflow-tooltip="true" />
            <el-table-column label="项目类别" align="center" prop="projectType" width="70" :show-overflow-tooltip="true" />
            <el-table-column label="计划开始时间" align="center" prop="planStartTime" width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.planStartTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="计划完成时间" align="center" prop="planCompleTime" width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.planCompleTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="费用" align="center" prop="fee" width="70" />
            <el-table-column label="状态" align="center" prop="status" width="70">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.project_status" :value="scope.row.status" />
              </template>
            </el-table-column>
            <el-table-column label="创建人" align="center" prop="createName" width="100" :show-overflow-tooltip="true" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
              <template slot-scope="scope">
<!--                && scope.row.supplierId-->
                <el-button size="mini" type="text" icon="el-icon-edit"  v-if="scope.row.status!='5' && scope.row.status!='4' && scope.row.supplierId!=orgId"
                  @click="handleUpdate(scope.row, scope.$index)" title="编辑"></el-button>
<!--                <el-button size="mini" type="text" icon="el-icon-s-management" v-if="scope.row.projectType == '自建'"-->
<!--                  @click="handleLL(scope.row, scope.$index)" title="立项"></el-button>-->
<!--                v-if="scope.row.projectType == '自建' && scope.row.status == '2'"-->
                <el-button size="mini" type="text" icon="el-icon-check" @click="handleJF(scope.row, scope.$index)" title="结项" v-if=" scope.row.supplierId!=orgId && scope.row.status!='5' && scope.row.status!='4'"></el-button>
                <el-button size="mini" type="text" v-if="scope.row.status!='5' && scope.row.status!='4' && scope.row.supplierId!=orgId"
                  icon="el-icon-close" @click="handleZZ(scope.row)" title="终止"></el-button>
<!--                v-if="scope.row.projectType == '自建' && scope.row.status == '2'"-->
<!--                <el-button v-if="scope.row.projectType == '自建' && scope.row.status == '4'" size="mini" type="text"-->
<!--                  icon="el-icon-document-copy" @click="queryEvaluateFile(scope.row, scope.$index + 1)" title="评价"></el-button>-->
                <el-button size="mini" type="text" icon="el-icon-view"
                  @click="handleViewProject(scope.row)" title="查看"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-col>
      </el-row>
    </div>

    <!-- 自建项目弹窗 -->
    <el-dialog :title="title" :visible.sync="open" width="880px" append-to-body>
      <div class="sketch_content">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" :inline="true">
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目编号" prop="projectNo">
                <el-input v-model="form.projectNo" style="width:250px" placeholder="请输入项目编号" :disabled="ReadOnly"
                  :maxlength="30" />
              </el-form-item>
              <el-form-item label="项目名称" prop="projectName">
                <el-input v-model="form.projectName" style="width:250px" placeholder="请输入项目名称" :disabled="ReadOnly"
                  :maxlength="50" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目负责人" prop="projectHead">
                <el-input v-model="form.projectHead" style="width:250px" placeholder="请输入项目负责人" :disabled="ReadOnly"
                  :maxlength="50" />
              </el-form-item>
              <el-form-item label="项目团队成员" prop="projectMember">
                <el-input v-model="form.projectMember" style="width:250px" placeholder="请输入项目团队成员" :disabled="ReadOnly"
                  :maxlength="1000" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目类别" prop="projectType">
                <el-select v-model="form.projectType" placeholder="请选择项目类别"
                  @change="changeProjectType(form.projectType)" :disabled="ReadOnly" style="width:250px">
                  <el-option value="自建">自建</el-option>
                  <el-option value="外协">外协</el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="状态" prop="status">
                <el-select v-model="form.status" placeholder="请选择状态" :disabled="true" style="width:250px">
                  <el-option v-for="dict in dict.type.project_status" :key="dict.value" :label="dict.label"
                    :value="dict.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
<!--              <el-form-item label="客户名称" prop="enterpriseName">-->
<!--                <el-input v-model="form.enterpriseName" placeholder="请输入客户名称" style="width:250px" :maxlength="10"-->
<!--                  :disabled="ReadOnly" />-->
<!--              </el-form-item>-->
              <el-form-item label="费用" prop="fee">
                <el-input v-model="form.fee" style="width:250px" placeholder="请输入费用" :disabled="ReadOnly" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="计划开始时间" prop="planStartTime">
                <el-date-picker clearable v-model="form.planStartTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择计划开始时间" style="width: 250px" :disabled="ReadOnly">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="计划完成时间" prop="planCompleTime">
                <el-date-picker clearable v-model="form.planCompleTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择计划完成时间" style="width: 250px" :disabled="ReadOnly">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="供应商" prop="supplierName">
                <el-input v-model="form.supplierName" placeholder="请点击选择供应商" style="width:610px" :maxlength="10"
                  :disabled="supplierNameReadOnly" @focus="enterpriseShow" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="项目介绍" prop="projectIntroduce">
                <el-input v-model="form.projectIntroduce" type="textarea" :disabled="ReadOnly" style="width:610px"
                  :maxlength="3000" placeholder="请输入项目介绍" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="项目目标" prop="projectTarget">
                <el-input v-model="form.projectTarget" type="textarea" style="width:610px" :disabled="ReadOnly"
                  :maxlength="3000" placeholder="请输入项目目标" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" :disabled="ReadOnly" style="width:610px"
                  :maxlength="3000" placeholder="请输入备注" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="附件">
                <file-view :type="typeSelf" :businessId="form.fileUpload" :businessCode="uploadCode" @change="getFile"
                  :key="refreshKey"></file-view>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="showReadOnly">保 存</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>


    <!-- ***************供应商弹窗选择界面************************************* -->
    <el-dialog title="供应商选择" :visible.sync="openSupplier" width="800px" append-to-body>
      <el-row>
        <el-col :span="24">
          <el-form :model="queryEnterpriseParams" ref="queryFormEnterprise" size="small" :inline="true"
            v-show="showSearch" label-width="100px">
            <el-form-item label="企业名称" prop="enterpriseName">
              <el-input v-model="queryEnterpriseParams.enterpriseName" placeholder="请输入企业名称" clearable
                @keyup.enter.native="handleQueryEnterprise" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryEnterprise">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQueryEnterprise">重置</el-button>
              <el-button type="primary" size="mini" @click="saveSelectEnterprise">确定</el-button>
            </el-form-item>
          </el-form>
          <el-table ref="tableEnterprise" v-loading="loading" style="width: 100%"
            @selection-change="handleSelectionChangeEnterprise" :data="supplierList">
            <el-table-column type="selection" width="45" align="center" />
            <el-table-column label="企业名称" align="center" prop="enterpriseName" />
            <el-table-column label="联系人" align="center" prop="contacts" />
            <el-table-column label="联系电话" align="center" prop="telephone" show-overflow-tooltip="true" />
          </el-table>
          <pagination v-show="total1 > 0" :total="total1" :page.sync="queryEnterpriseParams.pageNum"
            :limit.sync="queryEnterpriseParams.pageSize" @pagination="getEnterpriseList" />
        </el-col>
      </el-row>
    </el-dialog>
    <!-- ***************************************************************************** -->

    <!-- 自建项目交付弹窗 -->
    <el-dialog :title="titleJF" :visible.sync="openJF" width="880px" class="roll-dialog" append-to-body>
      <div class="sketch_content">
        <el-form ref="formJF" :model="formJF" :rules="rulesJF" label-width="100px" :inline="true">
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目编号" prop="projectNo">
                <el-input v-model="formJF.projectNo" style="width:250px" placeholder="请输入项目编号" :disabled="true" />
              </el-form-item>
              <el-form-item label="项目名称" prop="projectName">
                <el-input v-model="formJF.projectName" style="width:250px" placeholder="请输入项目名称" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目负责人" prop="projectHead">
                <el-input v-model="formJF.projectHead" style="width:250px" placeholder="请输入项目负责人" :disabled="true" />
              </el-form-item>
              <el-form-item label="项目团队成员" prop="projectMember">
                <el-input v-model="formJF.projectMember" style="width:250px" placeholder="请输入项目团队成员" :disabled="true"
                  :maxlength="1000" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目类别" prop="projectType">
                <el-select v-model="formJF.projectType" placeholder="请选择项目类别" :disabled="true" style="width:250px">
                  <el-option value="自建">自建</el-option>
                  <el-option value="外协">外协</el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="状态" prop="status">

                <el-select v-model="formJF.status" placeholder="请选择状态" :disabled="true" style="width:250px">
                  <el-option v-for="dict in dict.type.project_status" :key="dict.value" :label="dict.label"
                    :value="dict.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="客户名称" prop="enterpriseName">
                <el-input v-model="formJF.enterpriseName" placeholder="请输入客户名称" style="width:250px" :maxlength="10"
                  :disabled="true" />
              </el-form-item>
              <el-form-item label="费用" prop="fee">
                <el-input v-model="formJF.fee" style="width:250px" placeholder="请输入费用" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="计划开始时间" prop="planStartTime">
                <el-date-picker clearable v-model="formJF.planStartTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择计划开始时间" style="width: 250px" :disabled="true">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="计划完成时间" prop="planCompleTime">
                <el-date-picker clearable v-model="formJF.planCompleTime" type="date" value-format="yyyy-MM-dd"
                  placeholder="请选择计划完成时间" style="width: 250px" :disabled="true">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="供应商" prop="supplierName">
                <el-input v-model="formJF.supplierName" placeholder="请点击选择供应商" style="width:610px" :maxlength="10"
                  :disabled="true" @focus="enterpriseShow" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="项目介绍" prop="projectIntroduce">
                <el-input v-model="formJF.projectIntroduce" type="textarea" :disabled="true" style="width:610px"
                  :maxlength="3000" placeholder="请输入项目介绍" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="项目目标" prop="projectTarget">
                <el-input v-model="formJF.projectTarget" type="textarea" style="width:610px" :disabled="true"
                  :maxlength="3000" placeholder="请输入项目目标" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="备注" prop="remark">
                <el-input v-model="formJF.remark" type="textarea" :disabled="true" style="width:610px" :maxlength="3000"
                  placeholder="请输入备注" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 80px;">
              <el-form-item label="附件">
                <file-view :type="typeSelf" :businessId="formJF.fileUpload" :businessCode="uploadCode" @change="getFile"
                  :key="refreshKey"></file-view>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="交付人" prop="projectDeliveryPerson" v-if="formJF.status != '5'">
                <el-input v-model="formJF.projectDeliveryPerson" :disabled="ReadOnlyJF" style="width:250px"
                  placeholder="请输入交付人" :maxlength="10" />
              </el-form-item>
              <el-form-item label="交付时间" prop="deliveryTime" v-if="formJF.status != '5'">
                <el-date-picker clearable v-model="formJF.deliveryTime" :disabled="ReadOnlyJF" type="date"
                  value-format="yyyy-MM-dd" placeholder="请选择交付时间" style="width: 250px">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="项目合作方" prop="projectPartner" v-if="formJF.status != '5'">
                <el-input v-model="formJF.projectPartner" :disabled="ReadOnlyJF" placeholder="请输入项目合作方"
                  style="width:250px" :maxlength="30" />
              </el-form-item>
              <el-form-item label="项目核算" prop="projectAccounting" v-if="formJF.status != '5'">
                <el-input v-model="formJF.projectAccounting" :disabled="ReadOnlyJF" style="width:250px"
                  placeholder="请输入项目核算" :maxlength="50" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="项目完成情况" prop="projectAccomplish" v-if="formJF.status != '5'">
                <el-input v-model="formJF.projectAccomplish" :disabled="ReadOnlyJF" type="textarea" style="width:610px"
                  :maxlength="3000" placeholder="请输入项目完成情况" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="合作方评价" prop="partnerEvaluate" v-if="formJF.status != '5'">
                <el-input v-model="formJF.partnerEvaluate" :disabled="ReadOnlyJF" type="textarea" style="width:610px"
                  :maxlength="3000" placeholder="请输入合作方评价" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="项目评价" prop="projectEvaluate" v-if="formJF.status != '5'">
                <el-input v-model="formJF.projectEvaluate" :disabled="ReadOnlyJF" type="textarea" style="width:610px"
                  :maxlength="3000" placeholder="请输入项目评价" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="height: 55px;">
              <el-form-item label="成果交付" v-if="formJF.status != '5'">
                <file-view :type="typeSelfJF" :businessId="businessIdJF" :businessCode="uploadCodeJF" @change="getFile"
                  :key="refreshKey"></file-view>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormJF" v-if="showReadOnlyJF">交 付</el-button>
        <el-button @click="cancelJF">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 项目履历列表弹窗 -->
    <el-dialog title="自建项目履历" :visible.sync="recordOpen" width="1000px" append-to-body>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddLL"
            v-if="isShowRecord">新增</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getListRecord"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :row-style="{ height: '30px' }" border :cell-style="{ padding: '0px' }"
        height="350px" :data="recordList" @selection-change="handleSelectionChange">
        <el-table-column label="序号" type="index" :index="indexMethodLL" align="center" />
        <el-table-column label="跟进人" align="center" prop="creationName" width="120" :show-overflow-tooltip="true" />
        <el-table-column label="跟进时间" align="center" prop="creationTime" width="120" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更进内容" align="center" prop="content" width="250" :show-overflow-tooltip="true" />
        <el-table-column label="备注" align="center" prop="remark" width="250" :show-overflow-tooltip="true" />
        <el-table-column label="附件" align="center" prop="url">
          <template slot-scope="scope">
            <el-button v-if="scope.row.url != null" @click="queryUploadFile(scope.row, scope.$index + 1)" size="small"
              type="text">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" v-if="isShowRecord"
              @click="handleUpdateLL(scope.row)"></el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" v-if="isShowRecord"
              @click="handleDeleteLL(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="totalRecord > 0" :total="totalRecord" :page.sync="queryParamsRecord.pageNum"
        :limit.sync="queryParamsRecord.pageSize" @pagination="getListRecord" />
    </el-dialog>
    <!-- 添加或修改自建项目履历对话框 -->
    <el-dialog :title="titleLL" :visible.sync="openLL" width="680px" append-to-body>
      <el-form ref="formLL" :model="formLL" :rules="rulesLL" label-width="80px" :inline="true">
        <el-row>
          <el-col style="height: 55px;">
            <el-form-item label="跟进人" prop="creationName">
              <el-input v-model="formLL.creationName" disabled="true" placeholder="请输入跟进人" style="width:220px" />
            </el-form-item>
            <el-form-item label="跟进时间" prop="creationTime">
              <el-input v-model="formLL.creationTime" disabled="true" style="width:220px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="更进内容" prop="content">
              <el-input v-model="formLL.content" type="textarea" placeholder="请输入更进内容" style="width:530px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="formLL.remark" type="textarea" placeholder="请输入内容" style="width:530px" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col style="height: 55px;">
            <el-form-item label="附件">
              <file-view :type="typeSelfLL" :businessId="businessIdLL" :businessCode="uploadCodeLL" @change="getFile"
                :key="refreshKey"></file-view>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormLL">保 存</el-button>
        <el-button @click="cancelLL">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 查看履历附件 -->
    <el-dialog title="查看履历附件" :visible.sync="openFileList" width="600px" append-to-body>
      <el-table :data="fileList" height="300px" :row-style="{ height: '30px' }" border :cell-style="{ padding: '0px' }">
        <el-table-column label="序号" type="index" align="center" :index="indexMethodFile" />
        <el-table-column label="文件名称" align="center" prop="fileName" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-view" @click.stop="handleView(scope.row.url)"></el-button>
            <el-button size="mini" type="text" icon="el-icon-download"
              @click="handleDownload(scope.row.url, scope.row.fileName)"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 图片预览 -->
    <el-dialog :visible.sync="dialogVisible" append-to-body>
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    <!-- pdf预览 -->
    <el-dialog :visible.sync="dialogVisiblePdf" append-to-body>
      <pdf v-for="item in pageTotal" :src="pdfUrl" :key="item" :page="item"></pdf>
    </el-dialog>
    <div v-if="isForeign == 1">
      <Detail @change="close"></Detail>
    </div>
    <div v-if="type == 1">
      <Operate @change="closeOpt" :opt="edit" :id="id" :index="indexSelf" :state="state" :sign="sign"></Operate>
    </div>
    <!-- 交付物选择界面 -->
    <el-dialog title="项目交付物" :visible.sync="openFile" width="900px" append-to-body>
      <el-row>
        <el-col>
          <el-table v-loading="loading" height="300px" :row-style="{ height: '30px' }" border
            :cell-style="{ padding: '0px' }" ref="table" :data="evaluateList">
            <el-table-column label="序号" type="index" align="center" prop="index" :index="indexMethod"></el-table-column>
            <el-table-column label="文件名称" align="center" prop="fileName" :show-overflow-tooltip="true" width="200" />
            <el-table-column label="文件类型" align="center" prop="fileType" width="100" />
            <el-table-column label="创建人" align="center" prop="organizationName" width="200" />
            <el-table-column label="创建时间" align="center" prop="creationTime" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="是否同步" align="center" prop="isSyn" :show-overflow-tooltip="true"
              :formatter="formatterSyn">
            </el-table-column>
            <el-table-column label="操作" align="center" fixed="right" width="100" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit-outline" v-if="scope.row.isSyn == '0'"
                  @click="saveEvaluate(scope.row, scope.$index + 1)"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="totalFile > 0" :total="totalFile" :page.sync="queryParamsFile.pageNum"
            :limit.sync="queryParamsFile.pageSize" @pagination="getFileList" />
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelFile">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 同步交付附件选择界面 -->
    <!-- 文控同步界面 -->
    <el-dialog title="文控中心同步" :visible.sync="openFileWK" width="800px" append-to-body>
      <el-form ref="formFileWK" :model="formFileWK" :rules="rulesFileWK" label-width="100px" :inline="true">
        <el-row>
          <el-col>

            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number style="width: 250px" v-model="formFileWK.orderNum" controls-position="right" :min="0" />
            </el-form-item>
            <el-form-item label="文件柜名称" prop="cabinetId">
              <treeselect v-model="formFileWK.cabinetId" :readonly="true" :default-expand-level="3"
                :options="optionData" :normalizer="normalizer" :flat="true" :show-count="true" placeholder="请选择文件柜名称"
                style="width:250px" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="文件名称" prop="fileName">
              <el-input v-model="formFileWK.fileName" placeholder="请输入文件名称" style="width:250px" maxlength="50" />
            </el-form-item>
            <el-form-item label="文件编号" prop="documentNumber">
              <el-input v-model="formFileWK.documentNumber" placeholder="请输入文件编号" style="width:250px" maxlength="30" />
            </el-form-item>


          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <!-- <el-form-item label="生效时间" prop="effectiveTime">
              <el-date-picker clearable v-model="formFileWK.effectiveTime" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择生效时间" style="width:250px">
              </el-date-picker>
            </el-form-item> -->
            <el-form-item label="版本" prop="version">
              <el-input v-model="formFileWK.version" placeholder="请输入版本" style="width:250px" />
            </el-form-item>
            <el-form-item label="状态" prop="state">
              <el-select v-model="formFileWK.state" style="width: 250px" placeholder="请选择状态">
                <el-option v-for="dict in dict.type.file_status" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="建立时间" prop="establishmentTime">
              <el-input v-model="formFileWK.establishmentTime" style="width:250px" :disabled="true" />
            </el-form-item>
            <el-form-item label="建立人" prop="establishedName">
              <el-input v-model="formFileWK.establishedName" style="width:250px" :disabled="true" />
            </el-form-item>

          </el-col>
        </el-row>

      </el-form>
      <div style="text-align: right">
        <el-button type="primary" @click="submitFormFileWK">保 存</el-button>
        <el-button @click="cancelFileWK">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/project/selfRecord";
import { getProjectInfo } from "@/api/project/projectInfo";
import { listFileTreeInternal, addInternal, listInternal } from "@/api/file/internal";//文控中心 内部文件
import { addProject, delProject, getProject, listProject, updateClass, updateProject } from "@/api/project/self";
import { addEvaluateWK, listEvaluation, getEvaluation, delEvaluation, addEvaluation, updateEvaluation } from "@/api/project/evaluation";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import FileView from "@/components/FileView/index"
import pdf from 'vue-pdf'
import { queryFile, fileRemove, listFile, updateFile } from "@/api/system/file";
import { download } from "@/utils/request";
import Operate from "../query/operate.vue"
import Detail from "./detail.vue";
import { listInfoType, listInfo } from "@/api/supplier/supplier";
export default {
  name: "Project",
  components: { Treeselect, FileView, pdf, Detail, Operate },
  dicts: ['self_project_status', 'project_status', 'file_status'],
  data() {
    var supplierName = (rule, value, callback) => {
      if (!value && this.projectType == "外协") {
        return callback(new Error('外协项目请选择供应商'));
      }
      return callback()
    };
    return {
      optionData: null,
      showReadOnly: true,
      showReadOnlyJF: true,
      supplierNameReadOnly: true,
      queryEnterpriseParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseOrgId: null,
        enterpriseName: null,
        industry: null,
        industryType: null,
        belongTo: null,
      },
      fileId: '',
      fileList: [],
      projectType: null,
      openSupplier: false,
      type: 0,
      opt: 'add',
      state: null,
      sign: '',
      id: '',
      indexSelf: null,
      edit: 'edit',
      uploadCodeLL: "self_record",
      uploadCodeJF: "self_delivery",
      typeSelfJF: 0,
      typeSelfLL: 0,
      businessIdJF: null,
      businessIdLL: null,
      isForeign: 0,
      titleLL: "",
      openLL: false,
      //pdf预览
      openFileList: false,
      openFile: false,
      fileList: [],
      evaluateList: [],
      dialogImageUrl: '',
      dialogImageUrlPdf: '',
      pageTotal: null,
      dialogVisible: false,
      dialogVisiblePdf: false,
      queryParamsRecord: {
        pageNum: 1,
        pageSize: 15,
      },
      // 表单参数
      formLL: {

      },
      formFile: {

      },
      formFileWK: {},
      openFileWK: false,
      // 表单校验
      rulesLL: {
        content: [{ required: true, message: '请输入更进内容', trigger: 'blur' },
        { max: 2000, message: '更进内容长度不能超过2000个字符', trigger: 'blur' }
        ],
        remark: [
          { max: 2000, message: '备注长度不能超过2000个字符', trigger: 'blur' }
        ],
      },
      //文控 表单校验
      rulesFileWK: {
        fileName: [
          { required: true, message: "文件名称不能为空", trigger: "blur" },
          { max: 50, message: '文件名称长度不能超过50个字符', trigger: 'blur' }
        ],
        documentNumber: [
          { required: true, message: "文件编号不能为空", trigger: "blur" },
          { max: 50, message: '文件编号不能超过50个字符', trigger: 'blur' }
        ],
        cabinetId: [
          { required: true, message: "文件柜名称不能为空", trigger: "change" }
        ],
        effectiveTime: [
          { required: true, message: "生效时间不能为空", trigger: "change" }
        ],
        state: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
        version: [
          { required: true, message: "版本不能为空", trigger: "blur" },
          { max: 30, message: '版本不能超过30个字符', trigger: 'blur' }
        ],
      },
      recordOpen: false,
      isShow: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      orgId: null,
      // 总条数
      total: 0,
      // 自建项目表格数据
      projectList: [],
      addSign: 0,
      ReadOnly: false,
      ReadOnlyJF: false,
      title: "",
      open: false,
      titleWX: "添加外协项目",
      openWX: false,
      titleJF: "自建项目交付",
      openJF: false,
      typeCode: 'self',
      uploadCode: 'self',
      enterIds: [],
      //主分类
      options: null,
      showUpload: false,
      projectIds: [],
      typeSelf: 0,
      classOpen: false,
      classificationIds: '650c44e1-b575-4b62-9d54-1ba9d1e8abb7',
      projectIdLL: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        projectName: null,
        status: null,
      },
      // 表单参数
      form: {},
      formWX: {},
      formJF: {},
      totalRecord: 0,
      refreshKey: 0,
      // 自建项目履历表格数据
      recordList: [],
      // 表单校验
      rules: {
        supplierName: [{ required: true, validator: supplierName, trigger: 'change' }],
        projectNo: [{ required: true, message: '请输入项目编号', trigger: 'blur' },
        { max: 30, message: '项目编号不能超过30个字符', trigger: 'blur' }
        ],
        projectName: [{ required: true, message: '请输入项目名称', trigger: 'blur' },
        { max: 50, message: '项目名称不能超过50个字符', trigger: 'blur' }
        ],
        enterpriseName: [{ required: true, message: '请输入客户名称', trigger: 'blur' },
        { max: 50, message: '客户名称不能超过50个字符', trigger: 'blur' }
        ],
        projectHead: [{ required: true, message: '请输入项目负责人', trigger: 'blur' },
        { max: 50, message: '项目负责人不能超过50个字符', trigger: 'blur' }
        ],
        projectMember: [
          { max: 900, message: '项目团队成员不能超过900个字符', trigger: 'blur' }
        ],
        projectIntroduce: [
          { max: 2000, message: '项目介绍不能超过2000个字符', trigger: 'blur' }
        ],
        projectTarget: [
          { max: 2000, message: '项目目标不能超过2000个字符', trigger: 'blur' }
        ],
        remark: [
          { max: 2000, message: '备注不能超过2000个字符', trigger: 'blur' }
        ],
        //status: [{ required: true, message: '请选择状态', trigger: 'change' }],
        projectType: [{ required: true, message: '请选择项目类别', trigger: 'change' }],
        planStartTime: [
          { required: true, message: '请选择计划开始时间', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const planCompleTime = this.form.planCompleTime;
              if (value && planCompleTime && value > planCompleTime) {
                callback(new Error('计划开始时间不能大于计划完成时间'));
              } else {
                callback();
              }
            },
            trigger: 'change',
          },
        ],
        planCompleTime: [
          { required: true, message: '请选择计划完成时间', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const planStartTime = this.form.planStartTime;
              if (value && planStartTime && value < planStartTime) {
                callback(new Error('计划完成时间不能小于计划开始时间'));
              } else {
                callback();
              }
            },
            trigger: 'change',
          },
        ],
        fee: [{ required: true, message: '请输入费用', trigger: 'blur' },
        {
          pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
          message: "请输入正确的金额，可保留两位小数",
          trigger: "blur"
        }
        ],
        // ... other rules
      },

      // 表单校验
      rulesJF: {
        deliveryTime: [
          { required: true, message: '请选择交付时间', trigger: 'blur' },
        ],
        projectAccounting: [{ required: true, message: '请输入项目核算', trigger: 'blur' },
        { max: 50, message: '项目核算不能超过50个字符', trigger: 'blur' }],
        projectPartner: [{ required: true, message: '请输入项目合作方', trigger: 'blur' },
        { max: 500, message: '项目合作方不能超过500个字符', trigger: 'blur' }],
        projectAccomplish: [{ required: true, message: '请输入项目完成情况', trigger: 'blur' },
        { max: 1000, message: '项目完成情况不能超过1000个字符', trigger: 'blur' }],
        projectDeliveryPerson: [{ required: true, message: '请输入交付人', trigger: 'blur' },
        { max: 30, message: '交付人不能超过30个字符', trigger: 'blur' }
        ],
        partnerEvaluate: [
          { max: 2000, message: '合作方评价不能超过2000个字符', trigger: 'blur' }
        ],
        projectEvaluate: [
          { max: 2000, message: '项目评价不能超过2000个字符', trigger: 'blur' }
        ],
        // ... other rules
      },
      // 查询参数
      queryParamsFile: {
        pageNum: 1,
        pageSize: 15,
        businessId: null,
        businessCode: null,
        fileName: null
      },
      isShowRecord: false,
      supplierList: [],
      openSupplier: false,
      eIds: [],
      eName: [],
      total1: 0,
      totalFile: 0,
      projectIdJF: ""
    };
  },
  created() {
    this.getList();
    this.listFileTreeInternal();
    this.orgId=this.$store.state.user.info.orgId;
  },
  methods: {
    formatterSyn(row, column, cellValue, index) {
      var s = "";
      if (row.isSyn == "1") {
        s = "已同步";
      } else {
        s = "未同步";
      }
      return s;
    },
    //查询交付物文件
    getFileList() {
      //this.resetEvaluation();
      this.queryParamsFile.businessId = this.projectIdJF
      this.queryParamsFile.businessCode = 'self_delivery'
      //this.queryParamsFile.content = 0
      this.loading = true;
      listFile(this.queryParamsFile).then(response => {
        this.evaluateList = response.rows;
        this.totalFile = response.total;
        this.loading = false;
      });
    },
    //查询交付文件--用于同步
    queryEvaluateFile(row) {
      this.projectIdJF = row.projectId
      this.openFile = true;
      this.getFileList();
    },
    //加载文件柜树
    listFileTreeInternal() {
      listFileTreeInternal().then(res => {
        this.optionData = res.data;
      })
    },
    //禁用父节点
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        isDisabled: node.parentId == '00000000-0000-0000-0000-000000000000' ? true : false,
        children: node.children

      }
    },
    //同步按钮 弹页面
    saveEvaluate(row) {
      this.resetWX();
      this.fileId = row.id;
      this.formFileWK.fileName = row.fileName;//文件名称
      this.formFileWK.establishedName = this.$store.state.user.name;
      this.formFileWK.establishedId = this.$store.state.user.info.userId;
      this.formFileWK.establishmentTime = this.parseTime(new Date(), '{y}-{m}-{d}');
      this.openFileWK = true;
      this.formFileWK.orderNum = 0;
      this.openFile = false
    },
    //文控同步 提交按钮
    submitFormFileWK() {
      this.$refs["formFileWK"].validate(valid => {
        if (valid) {
          listInternal(this.formFileWK).then(response => {
            if (response.total > 0) {
              this.$message.error('该文件已同步到文控中心，不能重复同步！');
              return;
            } else {
              this.formFileWK.internalId = this.guid();
              addInternal(this.formFileWK).then(response => {
                this.$modal.msgSuccess("文控中心同步成功");
                this.openFile = true;
                this.openFileWK = false;
                this.getFileList();

              });
              const form = {
                id: this.fileId,
                isSyn: "1"
              }
              updateFile(form).then(response => { });
              //原附件信息
              this.formFile.fileSize = "1"//文件大小 暂存同步类型 1=文控 2=资质
              this.formFile.businessId = this.fileId
              this.formFile.content = this.formFileWK.internalId;//备注 暂存新附件的businessid
              this.formFile.businessCode = "project_delivery"
              this.formFile.newFileName = this.formFileWK.fileName;//新附件 暂存文本输入的文件名称
              //往文件表插入数据
              addEvaluateWK(this.formFile).then(response => {
              });
            }

          }).catch(function (error) {
            this.$message.error('系统错误,请联系管理员！');
          });

        }
      });
    },
    cancelFile() {
      this.openFile = false;
    },
    cancelFileWK() {
      this.openFileWK = false;
      this.getFileList()
    },
    //供应商选择
    enterpriseShow() {
      this.getEnterpriseList();
      setTimeout(() => {
        this.openSupplier = true;
      }, 300);
    },
    saveSelectEnterprise() {
      if (this.eIds.toString() == "" || this.eIds.toString() == null) {
        this.$modal.msgError("请先选择供应商！");
      } else {
        this.$set(this.form, 'supplierName', this.eName.toString())
        this.$set(this.form, 'supplierId', this.eIds.toString())
        this.closeSupplier()
      }
    },
    closeSupplier() {
      this.openSupplier = false
    },
    handleSelectionChangeEnterprise(selection) {
      if (selection.length > 1) {
        this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
        this.$refs.tableEnterprise.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.eIds = selection.map(item => item.enterpriseOrgId)
        this.eName = selection.map(item => item.enterpriseName)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      }
    },
    //项目类别按钮变化事件
    changeProjectType(value) {
      this.projectType = value
      if (value == "外协") {
        this.form.status = "2"
        this.supplierNameReadOnly = false
      } else {
        this.form.status = "2"//实施
        this.supplierNameReadOnly = true
      }
    },
    getEnterpriseList() {
      this.loading = true;
      this.queryEnterpriseParams.enterpriseOrgId = this.$store.state.user.info.orgId;
      this.queryEnterpriseParams.belongTo = this.$store.state.user.info.orgId;
      listInfo(this.queryEnterpriseParams).then(response => {
        this.supplierList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQueryEnterprise() {
      this.queryEnterpriseParams.pageNum = 1;
      this.getEnterpriseList();
    },
    /** 重置按钮操作 */
    resetQueryEnterprise() {
      this.resetForm("queryFormEnterprise");
      this.handleQueryEnterprise();
    },
    close() {
      this.$emit('change');
      this.isForeign = 0;
      this.getList();
    },
    closeOpt() {
      this.type = 0
      this.getList();
    },
    /** 新增项目履历按钮操作 */
    handleAddLL() {
      this.resetLL();
      this.refreshKey++;
      this.openLL = true;
      this.typeSelfLL = 1
      this.businessIdLL = this.guid();
      this.formLL.creationName = this.$store.state.user.name,
        this.formLL.creationTime = this.parseTime(new Date(), '{y}-{m}-{d}'),
        this.titleLL = "添加自建项目履历";
    },
    /** 修改项目履历按钮操作 */
    handleUpdateLL(row) {
      this.resetLL();
      this.refreshKey++;
      const id = row.id || this.ids
      this.typeSelfLL = 1
      this.businessIdLL = row.id
      getRecord(id).then(response => {
        this.formLL = response.data;
        this.openLL = true;
        this.titleLL = "修改自建项目履历";
      });
    },
    /** 履历提交按钮 */
    submitFormLL() {
      this.$refs["formLL"].validate(valid => {
        if (valid) {
          this.formLL.projectId = this.projectIdLL
          if (this.formLL.id != null) {
            updateRecord(this.formLL).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openLL = false;
              this.getListRecord();
            });
          } else {
            this.formLL.id = this.businessIdLL
            addRecord(this.formLL).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openLL = false;
              this.getListRecord();
            });
          }
        }
      });
    },
    //序号展示
    indexMethodFile(index) {
      return (this.queryParamsFile.pageNum - 1) * this.queryParamsFile.pageSize + index + 1;
    },
    //文件预览
    handleView(url) {
      if (url != null && url != '' && (url).indexOf('.pdf') !== -1) {
        this.handlePictureCardPreviewPdf(url);
      } else {
        this.handlePictureCardPreview(url);
      }
    },
    handlePictureCardPreview(url) {
      this.dialogImageUrl = url;
      this.dialogVisible = true;
    },
    //查询文件
    queryUploadFile(row) {
      queryFile(row.id, "self_record").then(response => {
        this.fileList = response.data;
        this.openFileList = true;
        console.log(this.fileList)
      });
    },

    // resetEvaluation() {
    //         this.formFileWK = {
    //             projectId:null,
    //             projectNumber:null,
    //             projectName:null,
    //             confirmationDescription:null,
    //             teacherRating:null,
    //             qualityScore:null,
    //             serviceRating:null,
    //             totalScore:null,
    //             evaluationDescription:null,
    //             evaluationDescription:null,
    //             teacherRating: null
    //         };
    //         this.resetForm("formFileWK");
    //     },
    //pdf预览
    handlePictureCardPreviewPdf(url) {
      this.pdfUrl = pdf.createLoadingTask(url)
      // 获取页码
      this.pdfUrl.promise.then(pdf => this.pageTotal = pdf.numPages).catch(error => {
      })
      this.dialogImageUrlPdf = url;
      this.dialogVisiblePdf = true;
    },
    //履历下载
    handleDownload(fileUrl, fileName) {
      let params = {
        resource: fileUrl
      }
      download("/common/download/resource", params, fileName);
    },
    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    },
    /** 删除按钮操作 */
    handleDeleteLL(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据项？').then(function () {
        return delRecord(ids);
      }).then(() => {
        this.getListRecord();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    // 表单重置
    resetLL() {
      this.formLL = {
        id: null,
        projectId: null,
        status: null,
        content: null,
        remark: null,
        createId: null,
        creationTime: null,
        creationName: null
      };
      this.resetForm("formLL");
    },
    // 表单重置
    resetJF() {
      this.formJF = {
        projectDeliveryPerson: null,
        deliveryTime: null,
        projectAccounting: null,
        projectPartner: null,
        projectEvaluate: null,
        projectAccomplish: null,
        partnerEvaluate: null
      };
      this.resetForm("formJF");
    },
    // 取消按钮
    cancelLL() {
      this.openLL = false;
      this.resetLL();
      this.getListRecord();
    },
    /** 查询自建项目列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getFile(data) {
      console.log(JSON.stringify(data))
    },

    //查看履历列表
    viewLL(row) {

      this.projectIdLL = row.projectId
      this.queryParamsRecord.projectId = row.projectId
      this.getListRecord();
    },

    //履历弹窗列表
    handleLL(row) {
      this.recordOpen = true
      if (row.status == "2") {
        this.isShowRecord = true
      } else {
        this.isShowRecord = false
      }
      this.projectIdLL = row.projectId
      this.queryParamsRecord.projectId = row.projectId
      this.getListRecord();
    },
    //详情项目弹窗
    handleViewProject(row) {
      //判断是自建还是外协 外协只看项目基本信息 自建看基本信息和交付信息
      getProject(row.projectId).then(response => {
        this.showReadOnly = false
        this.showReadOnlyJF = false
        this.ReadOnly = true;
        this.ReadOnlyJF = true;
        this.supplierNameReadOnly = true;
        if (row.projectType == "外协") {
          this.reset();
          this.form = response.data;
          this.open = true;
          this.title = "查看项目";
        } else {
          this.resetJF();
          this.businessIdJF = row.projectId
          this.formJF = response.data;
          this.openJF = true;

          this.titleJF = "查看项目";
        }
        this.addSign = 1;
        this.typeSelf = 2;
        this.typeSelfJF = 2;
        this.refreshKey++;
        //this.form.index = index + 1;

      });
    },
    /** 查询自建项目履历列表 */
    getListRecord() {
      this.loading = true;
      this.queryParamsRecord.projectId = this.projectIdLL
      listRecord(this.queryParamsRecord).then(response => {
        this.recordList = response.rows;
        this.totalRecord = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.typeSelf = 0;
      this.addSign = 0;
      this.reset();
    },
    // 取消按钮
    cancelWX() {
      this.openWX = false;
      this.addSign = 0;
      this.reset();
    },
    // 取消按钮
    cancelJF() {
      this.openJF = false;
      this.addSign = 0;
      this.reset();
    },
    resetWX() {
      this.formFileWK = {
        internalId: null,
        fileName: null,
        cabinetId: null,
        cabinetName: null,
        documentNumber: null,
        establishmentTime: null,
        establishedId: null,
        establishedName: null,
        effectiveTime: null,
        version: null,
        state: null,
        managementDepartment: null,
        changedId: null,
        changedName: null,
        updatedId: null,
        updatedNmae: null,
        operateTime: null,
        operateId: null,
        operateName: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        creationId: null,
        creationName: null,
        creationTime: null,
        belongTo: null
      };
      this.resetForm("formFileWK");
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        projectNo: null,
        projectName: null,
        enterpriseName: null,
        projectHead: null,
        planStartTime: null,
        planCompleTime: null,
        status: null,
        createId: null,
        createName: null,
        createTime: null,
        remark: null,
        fileUpload: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        classificationId: null,
        belongTo: null
      };
      this.resetForm("form");
    },
    closeDig() {
      this.typeSelf = 0;
      this.open = false;
      this.ReadOnly = false;
      this.getList();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.initStartDate = null;
      this.queryParams.endCompleDate = null;
      this.queryParams.endStartDate = null;
      this.queryParams.initCompleDate = null;
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.projectId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增自建项目按钮操作 */
    handleAddZJ() {
      this.reset();
      this.showReadOnly = true
      this.ReadOnly = false
      this.supplierNameReadOnly = true
      //this.form.projectType = '自建'
      //this.form.status = '2'
      this.form.fileUpload = new Date().getTime();
      this.addSign = 0;
      this.typeSelf = 0;
      this.refreshKey++;
      this.open = true;
      this.title = "添加项目";
    },
    // /** 新增自建项目按钮操作 */
    // handleAddWX() {
    //   this.isForeign = 1;
    // },
    //序号展示
    indexMethod(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    //序号展示
    indexMethodLL(index) {
      return (this.queryParamsRecord.pageNum - 1) * this.queryParamsRecord.pageSize + index + 1;
    },

    /** 修改按钮操作 */
    handleUpdate(row, index) {
      this.reset();
      this.ReadOnly = false
      this.showReadOnly = true
      const projectId = row.projectId || this.ids
      getProject(projectId).then(response => {
        this.form = response.data;
        if (row.projectType == "外协") {
          this.form.status = "7"
          this.supplierNameReadOnly = false
        } else {
          this.supplierNameReadOnly = true
        }
        this.open = true;
        this.addSign = 1;
        this.typeSelf = 1;
        this.refreshKey++;
        //this.form.index = index + 1;
        this.title = "修改自建项目";
      });
    },
    /** 交付按钮操作 */
    handleJF(row, index) {
      this.resetJF();
      this.showReadOnlyJF = true
      this.ReadOnlyJF = false
      this.businessIdJF = row.projectId
      const projectId = row.projectId || this.ids
      getProject(projectId).then(response => {
        this.formJF = response.data;
        this.refreshKey++;
        this.typeSelf = 2
        this.openJF = true;
        this.addSign = 1;
        this.typeSelfJF = 1;
        //this.formJF.index = index + 1;
        this.titleJF = "自建项目交付";
      });
    },
    //项目名称点击查询
    handleSelect(row, index) {
      if (row.projectType == "外协" && row.status != '7') {
        this.edit = "details";
        const id = row.classificationId;
        this.indexSelf = (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index;
        this.id = id;
        getProjectInfo(id).then(response => {
          if (row.status != "8") {
            this.sign = response.data.sign;
            this.state = response.data.state;
          }
          this.type = 1
        });
      } else {
        this.handleViewProject(row);
      }
    },

    /** 交付提交按钮 */
    submitFormJF() {
      this.$refs["formJF"].validate(valid => {
        if (valid) {
          this.$modal.confirm('交付成功后项目为完结状态，只能查看不允许修改，是否确认继续交付？').then(function () {
          }).then(() => {
            this.formJF.projectType = '自建'
            this.formJF.status = '4'
            updateProject(this.formJF).then(response => {
              this.$modal.msgSuccess("交付成功");
              this.openJF = false;
              this.getList();
            });
          }).catch(() => { });

        }
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.projectType == "外协") {
            this.$confirm('此操作会发送项目信息给指定供应商，是否继续？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              if (this.form.projectId != null) {
                updateProject(this.form).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                });
              } else {
                addProject(this.form).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                });
              }
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消保存'
              });
            });
          } else {
            if (this.form.projectId != null) {
              updateProject(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addProject(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }

        }
      });
    },
    /** 终止按钮 */
    handleZZ(row) {
      this.form.projectId = row.projectId
      this.form.projectType = '自建'
      this.form.status = '5'
      this.$modal.confirm('终止后此项目作废不能再修改，是否确认终止项目名称为"' + row.projectName + '"的数据项？').then(function () {
      }).then(() => {
        updateProject(this.form).then(response => {
          this.getList();
          this.$modal.msgSuccess("终止成功");
        });

      }).catch(() => { });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = row.projectId || this.ids;
      this.$modal.confirm('是否确认删除自建项目编号为"' + row.projectName + '"的数据项？').then(function () {
        return delProject(projectIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
  }
};
</script>
<style>
.sketch_content {
  /* //必须有高度 overflow 为自动 */
  overflow: auto;
  height: 434px;
  border-top: 1px solid #eff1f4;
  border-bottom: 1px solid #eff1f4;
  padding: 10px 30px 11px 27px;

  /* // 滚动条的样式,宽高分别对应横竖滚动条的尺寸 */
  &::-webkit-scrollbar {
    width: 3px;
  }

  /* // 滚动条里面默认的小方块,自定义样式 */
  &::-webkit-scrollbar-thumb {
    background: #8798AF;
    border-radius: 2px;
  }

  /* // 滚动条里面的轨道 */
  &::-webkit-scrollbar-track {
    background: transparent;
  }
}

.hyperlink {
  color: #007BFF;
  /* 蓝色 */
  text-decoration: underline;
  cursor: pointer;
}

.roll-dialog ::v-deep .el-dialog .el-dialog__body {
  padding: 3px 30px;
  overflow-y: scroll;
  height: 100px;
}
</style>
